package com.xbs.dao.enterprise;

import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.xbs.dao.conn.BaseDao;
import com.xbs.dao.conn.ParamSet;
import com.xbs.dao.conn.RowDatas;
import com.xbs.entity.EnterpriseOrderEntity;

public class EpOrderAdminDao extends BaseDao{
	/**
	 * 查询今天的自选订单
	 */
	public List<EnterpriseOrderEntity> getTodayEpOrder(String today){
		String sql="select eo_account,eo_order_id,eo_order_status,eo_plan_money,eo_fact_money,eo_rent_type,eo_remark,(to_days(now()) - to_days(eo_reserve_get_time)) days from tb_enterprise_order where eo_rent_type=0 and DATE_FORMAT(eo_establish_time,'%Y-%m-%d')=? and eo_fact_return_time is null";
		
		String sql1="select o.eo_account,o.eo_order_id,o.eo_order_status,o.eo_fact_return_time,o.eo_plan_money,o.eo_fact_money,o.eo_rent_type,o.eo_remark,(to_days(eo_fact_return_time) - to_days(eo_reserve_get_time)) days,m.rent_money*m.car_model_number as cash from tb_enterprise_order o,tb_enterprise_model m where eo_rent_type=0 and DATE_FORMAT(eo_establish_time,'%Y-%m-%d')=? and eo_fact_return_time is not null and o.eo_order_id=m.eo_order_id";
		
		RowDatas<EnterpriseOrderEntity> rd=new RowDatas<EnterpriseOrderEntity>() {
			
			@Override
			public EnterpriseOrderEntity getRowData(ResultSet rs) throws SQLException {
				EnterpriseOrderEntity e=new EnterpriseOrderEntity();
				e.setEo_account(rs.getString("eo_account"));
				e.setEo_order_id(rs.getString("eo_order_id"));
				e.setEo_order_status(rs.getString("eo_order_status"));
				e.setEo_plan_money(rs.getDouble("cash"));
				e.setEo_fact_money(rs.getDouble("eo_fact_money"));
				e.setEo_rent_type(rs.getInt("eo_rent_type"));
				e.setEo_remark(rs.getString("eo_remark"));
				e.setRentExpire(rs.getInt("days"));
				e.setEo_fact_return_time(rs.getDate("eo_fact_return_time"));
				return e;
			}
		};
		List<EnterpriseOrderEntity> ist=queryList(sql, new ParamSet(today),rd);
		List<EnterpriseOrderEntity> ist1=queryList(sql1, new ParamSet(today),rd);
		ist.addAll(ist1);
		return ist;
	}
	/**
	 * 根据企业订单编号修改状态
	 */
	public void updateZt(String id,String status){
		String sql="update tb_enterprise_order set eo_order_status=? where eo_order_id=?";
		updateExecuted(sql,new ParamSet(status,id));
	}
	/**
	 * 根据企业订单编号修改实际扣款金额
	 */
	public void updateJe(String id,Double cash){
		String sql="update tb_enterprise_order set eo_fact_money=? where eo_order_id=?";
		updateExecuted(sql,new ParamSet(cash,id));
	}
	/**
	 * 根据企业订单编号修改备注
	 */
	public void updateMark(String id,String mark){
		String sql="update tb_enterprise_order set eo_remark=? where eo_order_id=?";
		updateExecuted(sql,new ParamSet(mark,id));
	}
	/**
	 * 根据企业订单查看详情
	 */
	public void seedetail(String id,String detail){
		String sql="update tb_enterprise_order set eo_remark=? where eo_order_id=?";
		
		updateExecuted(sql,new ParamSet(detail,id));
	}
	/**
	 * 根据企业订单编号修改还车时间
	 */
	public void setreturntime(String id,Date returnTime){
		String sql="update tb_enterprise_order set eo_fact_return_time=? where eo_order_id=?";
		updateExecuted(sql,new ParamSet(returnTime,id));
	}
	
}
